<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Substitutes XIncludes in a DOMDocument Object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="domdocument.validate.html">« DOMDocument::validate</a></li>
      <li style="float: right;"><a href="class.domdocumentfragment.html">DOMDocumentFragment »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.domdocument.html">DOMDocument</a></li>
    <li>Substitutes XIncludes in a DOMDocument Object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="domdocument.xinclude" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMDocument::xinclude</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DOMDocument::xinclude</span> &mdash; <span class="dc-title">
   Substitutes XIncludes in a DOMDocument Object
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domdocument.xinclude-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMDocument::xinclude</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type">int</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   This method substitutes <a href="http://www.w3.org/TR/xinclude/" class="link external">&raquo;&nbsp;XIncludes</a> in a DOMDocument object.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Due to libxml2 automatically resolving entities, this method will produce
    unexpected results if the included XML file have an attached DTD.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-domdocument.xinclude-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       <a href="libxml.constants.html" class="link">libxml parameters</a>. Available
       since Libxml 2.6.7.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domdocument.xinclude-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the number of XIncludes in the document, -1 if some processing failed,
   or <strong><code>false</code></strong> if there were no substitutions.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-domdocument.xinclude-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5412">
    <p><strong>示例 #1 DOMDocument::xinclude() example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version="1.0"&nbsp;?&gt;<br />&lt;chapter&nbsp;xmlns:xi="http://www.w3.org/2001/XInclude"&gt;<br />&nbsp;&lt;title&gt;Books&nbsp;of&nbsp;the&nbsp;other&nbsp;guy..&lt;/title&gt;<br />&nbsp;&lt;para&gt;<br />&nbsp;&nbsp;&lt;xi:include&nbsp;href="book.xml"&gt;<br />&nbsp;&nbsp;&nbsp;&lt;xi:fallback&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;error&gt;xinclude:&nbsp;book.xml&nbsp;not&nbsp;found&lt;/error&gt;<br />&nbsp;&nbsp;&nbsp;&lt;/xi:fallback&gt;<br />&nbsp;&nbsp;&lt;/xi:include&gt;<br />&nbsp;&lt;/para&gt;<br />&lt;/chapter&gt;<br /></span><span style="color: #007700">EOD;<br /><br /></span><span style="color: #0000BB">$dom&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;let's&nbsp;have&nbsp;a&nbsp;nice&nbsp;output<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">preserveWhiteSpace&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">formatOutput&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;load&nbsp;the&nbsp;XML&nbsp;string&nbsp;defined&nbsp;above<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;substitute&nbsp;xincludes<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">xinclude</span><span style="color: #007700">();<br /><br />echo&nbsp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;chapter xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot;&gt;
  &lt;title&gt;Books of the other guy..&lt;/title&gt;
  &lt;para&gt;
    &lt;row xml:base=&quot;/home/didou/book.xml&quot;&gt;
       &lt;entry&gt;The Grapes of Wrath&lt;/entry&gt;
       &lt;entry&gt;John Steinbeck&lt;/entry&gt;
       &lt;entry&gt;en&lt;/entry&gt;
       &lt;entry&gt;0140186409&lt;/entry&gt;
      &lt;/row&gt;
    &lt;row xml:base=&quot;/home/didou/book.xml&quot;&gt;
       &lt;entry&gt;The Pearl&lt;/entry&gt;
       &lt;entry&gt;John Steinbeck&lt;/entry&gt;
       &lt;entry&gt;en&lt;/entry&gt;
       &lt;entry&gt;014017737X&lt;/entry&gt;
      &lt;/row&gt;
    &lt;row xml:base=&quot;/home/didou/book.xml&quot;&gt;
       &lt;entry&gt;Samarcande&lt;/entry&gt;
       &lt;entry&gt;Amine Maalouf&lt;/entry&gt;
       &lt;entry&gt;fr&lt;/entry&gt;
       &lt;entry&gt;2253051209&lt;/entry&gt;
      &lt;/row&gt;
  &lt;/para&gt;
&lt;/chapter&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>

</div></div></div></body></html>